<?php

# store the user_id in an easily accesiable variable
// TODO consider setting this as a constant
$user_id = $GLOBALS['user_id'];

# create a new user class for the person viewing this screen
$user = new user($user_id);
# Load user information required for this page from the database
$user_info[$user_id] = $user->load_tables('user_settings,user_stats,user_gladiator');

# Create a new graphic class to display user stats
$chart = new libchart();

echo 'Welcome Home, <b>'.  $user_info[$user_id]['username'] . '</b>.<BR>';


/********************************
*
*   MILITARY AND GLADIATOR SECTION
*
*               (Start)
*
**********************************/
echo '<br><h3>Military/Gladiator commitments</h3>';
# check user gladiator level (if any) and display apropriate content for their home
if ($user_info[$user_id]['glad_level'] > 0)
{
    $total_events = $user_info[$user_id]['event_wins'] + $user_info[$user_id]['event_draws'] + $user_info[$user_id]['event_loses'];
    if ($total_events > 0){ $rank = 'Gladiator'; } else { $rank = 'Tiro'; }
    $glad_status = 'You are a paloi <b>'. $user_info[$user_id]['glad_level'] . "</b> $rank.";
    $options = array();
    $options['/gladiator/'] = 'Go to the '.$user_info[$user_id]['establishment_name'];
}
elseif ($user_info[$user_id]['trainee_level'] > 0)
{
    $glad_status = 'You are a grade <b>'. $user_info[$user_id]['trainee_level'] . '</b> novicius (<i>trainee gladiator</i>).';
    $options = array();
    $options['/gladiator/'] = 'Go to the '.$user_info[$user_id]['establishment_name'];
}
else
{

    $glad_status = 'None.';
    $options = array();
    $options['/gladiator/vntr/'] = 'Volunteer (auctoratus) to become a gladiator';
    $options['/army/vntr/'] = 'Join the Army';
}
echo '<p>';
echo $glad_status;
echo '<br>';
echo player_options($options);
echo '</p>';
/********************************
*
*   MILITARY AND GLADIATOR SECTION
*
*    ZZZZZZZ    (END) ZZZZZZZZZZ
*
**********************************/


/********************************
*
*   FARMING SECTION
*
*               (Start)
*
**********************************/
echo '<br><h2>Farming</h2>';
    $options = array();
    $options['/serfdom/'] = 'Go farming';
echo '<p>';
echo 'This part will say if you own land or not (soon)';
// TODO display here if user has any land
echo '<br>';
echo player_options($options);
echo '</p>';

/********************************
*
*   FARMING SECTION
*
*    ZZZZZZZ    (END) ZZZZZZZZZZ
*
**********************************/

/********************************
*
*   Stats SECTION
*
*               (Start)
*
**********************************/
echo '<br><h2>Stats</h2>';
echo '<p>';

$chart = new VerticalBarChart(400, 250);

$potential = new XYDataSet();
    $potential->addPoint(new Point("Strength", 10));
    $potential->addPoint(new Point("Speed", 10));
    $potential->addPoint(new Point("Reflex", 10));
    $potential->addPoint(new Point("Coordination", 10));
    $potential->addPoint(new Point("Balance", 10));
    $potential->addPoint(new Point("Stamina", 10));

$actual = new XYDataSet();
    $actual->addPoint(new Point("Strength", $user_info[$user_id]['strength']));
    $actual->addPoint(new Point("Speed", $user_info[$user_id]['speed']));
    $actual->addPoint(new Point("Reflex", $user_info[$user_id]['reflex']));
    $actual->addPoint(new Point("Coordination", $user_info[$user_id]['coordination']));
    $actual->addPoint(new Point("Balance", $user_info[$user_id]['balance']));
    $actual->addPoint(new Point("Stamina", $user_info[$user_id]['stamina']));

$dataSet = new XYSeriesDataSet();
	$dataSet->addSerie("Actual", $actual);
	$dataSet->addSerie("MAX", $potential);
	$chart->setDataSet($dataSet);
	$chart->getPlot()->setGraphCaptionRatio(0.65);

$chart->setTitle($user_info[$user_id]['username'] . " stats");
$id_n_uid = $user_id .'_'. $user_info[$user_id]['uid'];
# Save the graphic we just made into a file
// TODO must remove the uid from the name to save any security risks
$chart->render($GLOBALS['config']['dir_ren'] ."$id_n_uid.png");

echo "<br><img src=\"http://www.europa100ad.com/rendered/$id_n_uid.png\"></img>";
echo '</p>';

/********************************
*
*   Stats SECTION
*
*    ZZZZZZZ    (END) ZZZZZZZZZZ
*
**********************************/

?>